{extend name="public:base"}

{block name="content"}
    <style>
        .upload_img_list{margin-top: 10px;}
    .upload_img_list > .img_list{display: inline-block;position: relative;margin-right:5px;background-color:#f9f9f9;border:1px solid #efefef;}
    .upload_img_list > .img_list > span{position:absolute;right:5px; top:5px; display: block; background-color:#f56c6c;height:20px;line-height: 20px;color:#fff;}
    .pear-input{
	height: 38px;
    line-height: 1.3;
    border-width: 1px;
    border-style: solid;
    background-color: #fff;
    color: rgba(0,0,0,.85);
    border-radius: 2px;
    border-color: #eee;
    transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
	display: block;
    width: 100%;
    padding-left: 10px;
}
    </style>
    <div class="layui-card">
        <div class="layui-card-body">
            <form class="layui-form layui-form-pane" action="">
                {neq name="domain_type" value="1"}
                <div class="layui-form-item">
                    <label class="layui-form-label">标题</label>
                    <div class="layui-input-block">
                        <input type="text" name="title" value="{$info.title|default=''}" autocomplete="off"
                            placeholder="请输入" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">描述</label>
                    <div class="layui-input-block">
                        <input type="text" name="description" value="{$info.description|default=''}"  autocomplete="off"
                            placeholder="请输入" class="layui-input">
                    </div>
                </div>
                {/neq}
                <div class="layui-form-item">
                    <label class="layui-form-label">跳转链接</label>
                    <div class="layui-input-block">
                        <input type="text" name="url" value="{$info.url|default=''}"  autocomplete="off"
                            placeholder="请输入" class="layui-input">
                    </div>
                </div>
                {neq name="domain_type" value="1"}
                <div class="layui-form-item">
                    <label class="layui-form-label">自动跳转(秒)</label>
                    <div class="layui-input-block">
                        <input type="number" name="auto_time" value="{$info.auto_time|default='999'}"  autocomplete="off"
                            placeholder="单位：秒" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">点击跳转</label>
                    <div class="layui-input-block">
                        <input type="checkbox" name="auto_click" value="1" lay-skin="switch" {present name="info.auto_click"} {eq name="info.auto_click" value="1"} checked {/eq} {/present}>
                        <div lay-checkbox>
                            开启 | 关闭
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">图片链接</label>
                    <div class="layui-input-block">
                        <button class="pear-btn pear-btn-primary" type="button" id="thumbBtn">图片上传</button>
                        <div class="upload_img_list" >
                            <div class="img_list" id="upload_box_thumb">
                                <img src="{$info.image_url|default='/assets/images/no_img.png'}" style="width:150px;max-width:150px" />
                                <input type="hidden" name="image_url" value="{$info.image_url|default=''}">
                            </div>
                            
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">年龄</label>
                    <div class="layui-input-block">
                        <input type="number" name="age" value="{$info.age|default='0'}"  autocomplete="off"
                            placeholder="" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">地区访问</label>
                    <div class="layui-input-block">
                        <input type="checkbox" name="area_type" value="1" lay-skin="switch" {present name="info.area_type"} {eq name="info.area_type" value="1"} checked {/eq} {/present}>
                        <div lay-checkbox>
                            允许 | 禁止
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">限制地区</label>
                    <div class="layui-input-block">
                        <select name="area" xm-select="demo1" xm-select-skin="default">
                            {volist name="area" id="vo"}
                            <option value="{$vo.id}" {present name="info.area"} {in name="vo.id" value="$info['area']"} selected {/in} {/present}>{$vo.name}</option>
                            {/volist}
                        </select>
                    </div>
                </div>
                {/neq}
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <input type="hidden" name="domain_id" value="{$info.domain_id|default=''}">
                        <input type="hidden" name="id" value="{$info.id|default=''}">
                        <button type="submit" class="pear-btn pear-btn-primary" lay-submit="" lay-filter="form-save">
                            <i class="layui-icon layui-icon-ok"></i> 提交
                        </button>
                </div>
                </div>        
            </form>
        </div>
    </div>


{/block} 
{block name="script"} 
<script>
    layui.use(['form','jquery','element','select','upload'], function() {
        let form = layui.form;
        let $ = layui.jquery;
        let select = layui.select;
        let upload =layui.upload;
        layui.upload.render({
			elem: '#thumbBtn'
			, url: '{:url("captcha/upload")}'
			, done: function (res) {
				//如果上传失败
				if (res.code != "200") {
					return layer.msg('上传失败');
				}
				//上传成功
				$('#upload_box_thumb input').attr('value', res.url);		
				$('#upload_box_thumb img').attr('src', res.url);
			}
		});
        form.on('submit(form-save)', function(data) {
            $.ajax({
                url: '{:url("form")}',
                data: JSON.stringify(data.field),
                dataType: 'json',
                contentType: 'application/json',
                type: 'post',
                success: function(result) {
                    if (result.code == '1') {
                        layer.msg(result.msg, {
                            icon: 1,
                            time: 1000
                        });
                    } else {
                        layer.msg(result.msg, {
                            icon: 2,
                            time: 1000
                        });
                    }
                }
            })
            return false;
        });
    })

</script>
{/block}
</html>
